var express = require('express');
var router = express.Router();
var sqlite3 = require('sqlite3').verbose();
var path = require('path');
/* GET users listing. */
router.get('/', function (req, res, next) {

    var db = new sqlite3.Database(path.join(__dirname, "../db/Delphi.s3db"));
    try {
        if (req.query.type == '1')
            sqlStr = "insert into s_expert(s_expert_id,s_expert_name,pwd) values(?,?,?)";
        else if (req.query.type == '2')
            sqlStr = "insert into p_expert(p_expert_id,p_expert_name,pwd) values(?,?,?)";
        else if (req.query.type == '3')
            sqlStr = "insert into admin(admin_id,admin_name,pwd) values(?,?,?)";
        else if (req.query.type == '4')
            sqlStr = "insert into visitor(visitor_id,visitor_name,pwd) values(?,?,?)";
        db.all(sqlStr, [req.query.username, req.query.truename, req.query.password], function (err, rows) {
            if (err == null)
                res.send('1');
            else {
                console.log(err);
                res.send('0');
            }
        });

    } catch (ex) {
        console.log(ex);
    }
});

module.exports = router;